package com.nobuyme.box.toy;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.nobuyme.box.R;
import com.pachong.android.baseuicomponent.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShareDetailFragment extends BaseFragment {
    @Bind(R.id.tv_share_content)
    TextView mTvShareContent;
    @Bind(R.id.viewGroup)
    LinearLayout group;
    private ArrayList<String> image_list;
    private String content;

    public ShareDetailFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, view);
        image_list = getArguments().getStringArrayList(ShareDetailActivity.IMGLIST);
        content = getArguments().getString(ShareDetailActivity.CONTENT);
        initData();
        return view;
    }

    private void initData() {
        if(image_list.size()>0){
        ImageView[] imageViews = new ImageView[image_list.size()];
        for (int i = 0; i < imageViews.length; i++){

            ImageView imageView = new ImageView(getActivity());
            imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            imageViews[i] = imageView;
            Glide.with(getActivity()).load(image_list.get(i)).into(imageView);
            group.addView(imageView);
        }
        }
        mTvShareContent.setText(content);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_share_detail, container, false);
        return inflate;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
